home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / portable / unctrl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  2.0 KB  |  80 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3. #undef    unctrl
  4.  
  5. #ifdef PDCDEBUG
  6. char *rcsid_unctrl = "$Header: C:\CURSES\portable\RCS\unctrl.c 2.1 1993/06/18 20:21:22 MH Rel MH $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12. static char strbuf[3] = {0, 0, 0};
  13.  
  14. /*man-start*********************************************************************
  15.  
  16.   unctrl()    - convert character to printable form
  17.  
  18.   X/Open Description:
  19.      The unctrl routine expands the character c into a character
  20.      string which is a printable representation of the character.
  21.  
  22.      Control characters are displayed in the ^X notation.  Printing
  23.      characters are displayed normally.
  24.  
  25.   PDCurses Description:
  26.      The conversion from a control character to a two-character
  27.      sequence is done by the unctrl() function. In the BSD version
  28.      of curses it is done by a macro, which uses a publicly
  29.      available translation table. Some ill-behaved application
  30.      programs use the table directly, and since it does not exist
  31.      in this curses version such application will link with an
  32.      error message complainting about undefined symbols.
  33.  
  34.   X/Open Return Value:
  35.      The unctrl() function returns OK on success and ERR on error.
  36.  
  37.   X/Open Errors:
  38.      No errors are defined for this function.
  39.  
  40.   Portability:
  41.      PDCurses    char* unctrl( chtype c );
  42.      X/Open Dec '88    char* unctrl( chtype c );
  43.      BSD Curses    char* unctrl( chtype c );
  44.      SYS V Curses    char* unctrl( chtype c );
  45.  
  46. **man-end**********************************************************************/
  47.  
  48. char*    unctrl(chtype c)
  49. {
  50.     chtype    ic = c;
  51.  
  52. #ifdef PDCDEBUG
  53.     if (trace_on) PDC_debug("unctrl() - called\n");
  54. #endif
  55.  
  56.     ic &= A_CHARTEXT;
  57.     if (ic >= 0x20 && ic != 0x7f)        /* normal characters */
  58.     {
  59.         strbuf[0] = (char) ic;
  60.         strbuf[1] = '\0';
  61.         return( strbuf );
  62.     }
  63.     strbuf[0] = '^';    /* '^' prefix */
  64.     if (c == 0x7f)
  65.     {
  66.         /*
  67.          * 0x7f == DEL
  68.          */
  69.         strbuf[1] = '?';
  70.     }
  71.     else
  72.     {
  73.         /*
  74.          * other control
  75.          */
  76.         strbuf[1] = (char)(ic + '@');
  77.     }
  78.     return( strbuf );
  79. }
  80.